<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>基本操作 | 机器学习（常用科学计算库的使用）基础定位、目标</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../Numpy/section4.html" />
    
    
    <link rel="prev" href="../Numpy/section2.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="4.3"
        data-chapter-title="基本操作"
        data-filepath="Numpy/section3.md"
        data-basepath=".."
        data-revision="Sat Jul 20 2019 23:53:14 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        机器学习（常用科学计算库的使用）基础定位、目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="ml_pre/index.html">
            
                
                    <a href="../ml_pre/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        机器学习概述
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="ml_pre/section1.html">
            
                
                    <a href="../ml_pre/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        人工智能概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="ml_pre/section2.html">
            
                
                    <a href="../ml_pre/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        人工智能发展历程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ml_pre/section3.html">
            
                
                    <a href="../ml_pre/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        人工智能主要分支
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ml_pre/section4.html">
            
                
                    <a href="../ml_pre/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        机器学习工作流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ml_pre/section5.html">
            
                
                    <a href="../ml_pre/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        机器学习算法分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="ml_pre/section6.html">
            
                
                    <a href="../ml_pre/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        模型评估
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="ml_pre/section7.html">
            
                
                    <a href="../ml_pre/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        Azure机器学习模型搭建实验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ml_pre/section8.html">
            
                
                    <a href="../ml_pre/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        深度学习简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="env/index.html">
            
                
                    <a href="../env/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        机器学习基础环境安装与使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="env/section1.html">
            
                
                    <a href="../env/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="env/section2.html">
            
                
                    <a href="../env/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        jupyter notebook使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="Matplotlib/index.html">
            
                
                    <a href="../Matplotlib/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Matplotlib
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="Matplotlib/section1.html">
            
                
                    <a href="../Matplotlib/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Matplotlib之HelloWorld
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="Matplotlib/section2.html">
            
                
                    <a href="../Matplotlib/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        基础绘图功能 — 以折线图为例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="Matplotlib/section3.html">
            
                
                    <a href="../Matplotlib/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        常见图形绘制
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Numpy/index.html">
            
                
                    <a href="../Numpy/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Numpy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Numpy/section1.html">
            
                
                    <a href="../Numpy/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Numpy的优势
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Numpy/section2.html">
            
                
                    <a href="../Numpy/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        N维数组-ndarray
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4.3" data-path="Numpy/section3.html">
            
                
                    <a href="../Numpy/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Numpy/section4.html">
            
                
                    <a href="../Numpy/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        ndarray运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Numpy/section5.html">
            
                
                    <a href="../Numpy/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        数组间的运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Numpy/section6.html">
            
                
                    <a href="../Numpy/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        数学：矩阵
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Pandas/index.html">
            
                
                    <a href="../Pandas/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Pandas/section1.html">
            
                
                    <a href="../Pandas/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Pandas/section2.html">
            
                
                    <a href="../Pandas/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Pandas数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="Pandas/section3.html">
            
                
                    <a href="../Pandas/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        基本数据操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Pandas/section4.html">
            
                
                    <a href="../Pandas/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        DataFrame运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Pandas/section5.html">
            
                
                    <a href="../Pandas/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Pandas画图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Pandas/section6.html">
            
                
                    <a href="../Pandas/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件读取与存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Pandas/section7.html">
            
                
                    <a href="../Pandas/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        高级处理-缺失值处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="Pandas/section8.html">
            
                
                    <a href="../Pandas/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        高级处理-数据离散化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="Pandas/section9.html">
            
                
                    <a href="../Pandas/section9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        高级处理-合并
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="Pandas/section10.html">
            
                
                    <a href="../Pandas/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        高级处理-交叉表与透视表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="Pandas/section11.html">
            
                
                    <a href="../Pandas/section11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        高级处理-分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="Pandas/section12.html">
            
                
                    <a href="../Pandas/section12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="ReadingExtension/index.html">
            
                
                    <a href="../ReadingExtension/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        拓展知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="ReadingExtension/1.完整机器学习项目的流程.html">
            
                
                    <a href="../ReadingExtension/1.完整机器学习项目的流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        完整机器学习项目的流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="ReadingExtension/2.独立同分布.html">
            
                
                    <a href="../ReadingExtension/2.独立同分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        独立同分布
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >机器学习（常用科学计算库的使用）基础定位、目标</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="43-&#x57FA;&#x672C;&#x64CD;&#x4F5C;">4.3 &#x57FA;&#x672C;&#x64CD;&#x4F5C;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x76EE;&#x6807;<ul>
<li>&#x7406;&#x89E3;&#x6570;&#x7EC4;&#x7684;&#x5404;&#x79CD;&#x751F;&#x6210;&#x65B9;&#x6CD5;</li>
<li>&#x5E94;&#x7528;&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x673A;&#x5236;&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x7684;&#x5207;&#x7247;&#x83B7;&#x53D6;</li>
<li>&#x5E94;&#x7528;&#x7EF4;&#x5EA6;&#x53D8;&#x6362;&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x7684;&#x5F62;&#x72B6;&#x6539;&#x53D8;</li>
<li>&#x5E94;&#x7528;&#x7C7B;&#x578B;&#x53D8;&#x6362;&#x5B9E;&#x73B0;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x6539;&#x53D8;</li>
<li>&#x5E94;&#x7528;&#x6570;&#x7EC4;&#x7684;&#x8F6C;&#x6362;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="1-&#x751F;&#x6210;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;">1 &#x751F;&#x6210;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;</h2>
<h3 id="11-&#x751F;&#x6210;0&#x548C;1&#x7684;&#x6570;&#x7EC4;">1.1 &#x751F;&#x6210;0&#x548C;1&#x7684;&#x6570;&#x7EC4;</h3>
<ul>
<li><strong>np.ones(shape, dtype)</strong></li>
<li>np.ones_like(a, dtype)</li>
<li><strong>np.zeros(shape, dtype)</strong></li>
<li>np.zeros_like(a, dtype)    </li>
</ul>
<pre><code class="lang-python">ones = np.ones([<span class="hljs-number">4</span>,<span class="hljs-number">8</span>])
ones
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;:</p>
<pre><code class="lang-python">array([[<span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>],
       [<span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>],
       [<span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>],
       [<span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>, <span class="hljs-number">1.</span>]])
</code></pre>
<pre><code class="lang-python">np.zeros_like(ones)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;:</p>
<pre><code class="lang-python">array([[<span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>],
       [<span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>],
       [<span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>],
       [<span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>, <span class="hljs-number">0.</span>]])
</code></pre>
<h3 id="12-&#x4ECE;&#x73B0;&#x6709;&#x6570;&#x7EC4;&#x751F;&#x6210;">1.2 &#x4ECE;&#x73B0;&#x6709;&#x6570;&#x7EC4;&#x751F;&#x6210;</h3>
<h4 id="121-&#x751F;&#x6210;&#x65B9;&#x5F0F;">1.2.1 &#x751F;&#x6210;&#x65B9;&#x5F0F;</h4>
<ul>
<li><p><strong>np.array(object, dtype)</strong></p>
</li>
<li><p><strong>np.asarray(a, dtype)</strong></p>
</li>
</ul>
<pre><code class="lang-python">a = np.array([[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]])
<span class="hljs-comment"># &#x4ECE;&#x73B0;&#x6709;&#x7684;&#x6570;&#x7EC4;&#x5F53;&#x4E2D;&#x521B;&#x5EFA;</span>
a1 = np.array(a)
<span class="hljs-comment"># &#x76F8;&#x5F53;&#x4E8E;&#x7D22;&#x5F15;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x5E76;&#x6CA1;&#x6709;&#x771F;&#x6B63;&#x7684;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;</span>
a2 = np.asarray(a)
</code></pre>
<h4 id="122-&#x5173;&#x4E8E;array&#x548C;asarray&#x7684;&#x4E0D;&#x540C;">1.2.2 &#x5173;&#x4E8E;array&#x548C;asarray&#x7684;&#x4E0D;&#x540C;</h4>
<p><img src="images/array&#x548C;asarray&#x7684;&#x533A;&#x522B;.png" alt="image-20190618211642426"></p>
<h3 id="13-&#x751F;&#x6210;&#x56FA;&#x5B9A;&#x8303;&#x56F4;&#x7684;&#x6570;&#x7EC4;">1.3 &#x751F;&#x6210;&#x56FA;&#x5B9A;&#x8303;&#x56F4;&#x7684;&#x6570;&#x7EC4;</h3>
<h4 id="131-nplinspace-start-stop-num-endpoint">1.3.1 np.linspace (start, stop, num, endpoint)</h4>
<ul>
<li>&#x521B;&#x5EFA;&#x7B49;&#x5DEE;&#x6570;&#x7EC4; &#x2014; &#x6307;&#x5B9A;&#x6570;&#x91CF;</li>
<li>&#x53C2;&#x6570;:<ul>
<li>start:&#x5E8F;&#x5217;&#x7684;&#x8D77;&#x59CB;&#x503C;</li>
<li>stop:&#x5E8F;&#x5217;&#x7684;&#x7EC8;&#x6B62;&#x503C;</li>
<li>num:&#x8981;&#x751F;&#x6210;&#x7684;&#x7B49;&#x95F4;&#x9694;&#x6837;&#x4F8B;&#x6570;&#x91CF;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;50</li>
<li>endpoint:&#x5E8F;&#x5217;&#x4E2D;&#x662F;&#x5426;&#x5305;&#x542B;stop&#x503C;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;ture</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x751F;&#x6210;&#x7B49;&#x95F4;&#x9694;&#x7684;&#x6570;&#x7EC4;</span>
np.linspace(<span class="hljs-number">0</span>, <span class="hljs-number">100</span>, <span class="hljs-number">11</span>)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([  <span class="hljs-number">0.</span>,  <span class="hljs-number">10.</span>,  <span class="hljs-number">20.</span>,  <span class="hljs-number">30.</span>,  <span class="hljs-number">40.</span>,  <span class="hljs-number">50.</span>,  <span class="hljs-number">60.</span>,  <span class="hljs-number">70.</span>,  <span class="hljs-number">80.</span>,  <span class="hljs-number">90.</span>, <span class="hljs-number">100.</span>])
</code></pre>
<h4 id="132-nparangestartstop-step-dtype">1.3.2 np.arange(start,stop, step, dtype)</h4>
<ul>
<li>&#x521B;&#x5EFA;&#x7B49;&#x5DEE;&#x6570;&#x7EC4; &#x2014; &#x6307;&#x5B9A;&#x6B65;&#x957F;</li>
<li>&#x53C2;&#x6570;<ul>
<li>step:&#x6B65;&#x957F;,&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;1</li>
</ul>
</li>
</ul>
<pre><code class="lang-python">np.arange(<span class="hljs-number">10</span>, <span class="hljs-number">50</span>, <span class="hljs-number">2</span>)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([<span class="hljs-number">10</span>, <span class="hljs-number">12</span>, <span class="hljs-number">14</span>, <span class="hljs-number">16</span>, <span class="hljs-number">18</span>, <span class="hljs-number">20</span>, <span class="hljs-number">22</span>, <span class="hljs-number">24</span>, <span class="hljs-number">26</span>, <span class="hljs-number">28</span>, <span class="hljs-number">30</span>, <span class="hljs-number">32</span>, <span class="hljs-number">34</span>, <span class="hljs-number">36</span>, <span class="hljs-number">38</span>, <span class="hljs-number">40</span>, <span class="hljs-number">42</span>,
       <span class="hljs-number">44</span>, <span class="hljs-number">46</span>, <span class="hljs-number">48</span>])
</code></pre>
<h4 id="133-nplogspacestartstop-num">1.3.3 np.logspace(start,stop, num)</h4>
<ul>
<li><p>&#x521B;&#x5EFA;&#x7B49;&#x6BD4;&#x6570;&#x5217;</p>
</li>
<li><p>&#x53C2;&#x6570;:</p>
<ul>
<li>num:&#x8981;&#x751F;&#x6210;&#x7684;&#x7B49;&#x6BD4;&#x6570;&#x5217;&#x6570;&#x91CF;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;50</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x751F;&#x6210;10^x</span>
np.logspace(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;:</p>
<pre><code class="lang-shell">array([  1.,  10., 100.])
</code></pre>
<h3 id="14-&#x751F;&#x6210;&#x968F;&#x673A;&#x6570;&#x7EC4;">1.4 &#x751F;&#x6210;&#x968F;&#x673A;&#x6570;&#x7EC4;</h3>
<h4 id="141-&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x4ECB;&#x7ECD;">1.4.1 &#x4F7F;&#x7528;&#x6A21;&#x5757;&#x4ECB;&#x7ECD;</h4>
<ul>
<li>np.random&#x6A21;&#x5757;</li>
</ul>
<h4 id="142-&#x6B63;&#x6001;&#x5206;&#x5E03;">1.4.2 &#x6B63;&#x6001;&#x5206;&#x5E03;</h4>
<h5 id="&#x4E00;&#x3001;&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x590D;&#x4E60;&#xFF1A;&#x6B63;&#x6001;&#x5206;&#x5E03;&#xFF08;&#x7406;&#x89E3;&#xFF09;">&#x4E00;&#x3001;&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x590D;&#x4E60;&#xFF1A;&#x6B63;&#x6001;&#x5206;&#x5E03;&#xFF08;&#x7406;&#x89E3;&#xFF09;</h5>
<h5 id="a-&#x4EC0;&#x4E48;&#x662F;&#x6B63;&#x6001;&#x5206;&#x5E03;">a. &#x4EC0;&#x4E48;&#x662F;&#x6B63;&#x6001;&#x5206;&#x5E03;</h5>
<p>&#x6B63;&#x6001;&#x5206;&#x5E03;&#x662F;&#x4E00;&#x79CD;&#x6982;&#x7387;&#x5206;&#x5E03;&#x3002;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x662F;&#x5177;&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x3BC;&#x548C;&#x3C3;&#x7684;&#x8FDE;&#x7EED;&#x578B;&#x968F;&#x673A;&#x53D8;&#x91CF;&#x7684;&#x5206;&#x5E03;&#xFF0C;&#x7B2C;&#x4E00;&#x53C2;&#x6570;&#x3BC;&#x662F;&#x670D;&#x4ECE;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;&#x968F;&#x673A;&#x53D8;&#x91CF;&#x7684;&#x5747;&#x503C;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x3C3;&#x662F;&#x6B64;&#x968F;&#x673A;&#x53D8;&#x91CF;&#x7684;&#x6807;&#x51C6;&#x5DEE;&#xFF0C;&#x6240;&#x4EE5;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x8BB0;&#x4F5C;<strong>N(&#x3BC;&#xFF0C;&#x3C3; )</strong>&#x3002;</p>
<p><img src="images/&#x6B63;&#x6001;&#x5206;&#x5E03;.png" alt=""></p>
<h5 id="b-&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;&#x5E94;&#x7528;">b. &#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;&#x5E94;&#x7528;</h5>
<p>&#x751F;&#x6D3B;&#x3001;&#x751F;&#x4EA7;&#x4E0E;&#x79D1;&#x5B66;&#x5B9E;&#x9A8C;&#x4E2D;&#x5F88;&#x591A;&#x968F;&#x673A;&#x53D8;&#x91CF;&#x7684;&#x6982;&#x7387;&#x5206;&#x5E03;&#x90FD;&#x53EF;&#x4EE5;&#x8FD1;&#x4F3C;&#x5730;&#x7528;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x6765;&#x63CF;&#x8FF0;&#x3002;</p>
<h5 id="c-&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7279;&#x70B9;">c. &#x6B63;&#x6001;&#x5206;&#x5E03;&#x7279;&#x70B9;</h5>
<p><strong>&#x3BC;&#x51B3;&#x5B9A;&#x4E86;&#x5176;&#x4F4D;&#x7F6E;&#xFF0C;&#x5176;&#x6807;&#x51C6;&#x5DEE;&#x3C3;</strong>&#x51B3;&#x5B9A;&#x4E86;&#x5206;&#x5E03;&#x7684;&#x5E45;&#x5EA6;&#x3002;&#x5F53;&#x3BC; = 0,&#x3C3; = 1&#x65F6;&#x7684;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x662F;&#x6807;&#x51C6;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x3002;</p>
<p>&#x6807;&#x51C6;&#x5DEE;&#x5982;&#x4F55;&#x6765;&#xFF1F;</p>
<ul>
<li><h6 id="&#x65B9;&#x5DEE;">&#x65B9;&#x5DEE;</h6>
</li>
</ul>
<p>&#x662F;&#x5728;&#x6982;&#x7387;&#x8BBA;&#x548C;&#x7EDF;&#x8BA1;&#x65B9;&#x5DEE;&#x8861;&#x91CF;&#x4E00;&#x7EC4;&#x6570;&#x636E;&#x65F6;&#x79BB;&#x6563;&#x7A0B;&#x5EA6;&#x7684;&#x5EA6;&#x91CF;</p>
<p><img src="image/image-20190620081842007.png" alt="image-20190620081842007"></p>
<p>&#x5176;&#x4E2D;M&#x4E3A;&#x5E73;&#x5747;&#x503C;&#xFF0C;n&#x4E3A;&#x6570;&#x636E;&#x603B;&#x4E2A;&#x6570;&#xFF0C;&#x3C3; &#x4E3A;&#x6807;&#x51C6;&#x5DEE;&#xFF0C;&#x3C3; ^2&#x200B;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E00;&#x4E2A;&#x6574;&#x4F53;&#x4E3A;&#x65B9;&#x5DEE;</p>
<p><img src="images/&#x6807;&#x51C6;&#x5DEE;&#x516C;&#x5F0F;.png" alt="&#x6807;&#x51C6;&#x5DEE;&#x516C;&#x5F0F;"></p>
<ul>
<li><h6 id="&#x6807;&#x51C6;&#x5DEE;&#x4E0E;&#x65B9;&#x5DEE;&#x7684;&#x610F;&#x4E49;"><strong>&#x6807;&#x51C6;&#x5DEE;&#x4E0E;&#x65B9;&#x5DEE;&#x7684;&#x610F;&#x4E49;</strong></h6>
</li>
</ul>
<p>&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x6210;&#x6570;&#x636E;&#x7684;&#x4E00;&#x4E2A;&#x79BB;&#x6563;&#x7A0B;&#x5EA6;&#x7684;&#x8861;&#x91CF;</p>
<p><img src="images/&#x79BB;&#x6563;&#x7A0B;&#x5EA6;.png" alt="&#x79BB;&#x6563;&#x7A0B;&#x5EA6;"></p>
<h5 id="&#x4E8C;&#x3001;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x521B;&#x5EFA;&#x65B9;&#x5F0F;">&#x4E8C;&#x3001;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x521B;&#x5EFA;&#x65B9;&#x5F0F;</h5>
<ul>
<li><p>np.random.randn(<em>d0, d1, &#x2026;, dn</em>)</p>
<p>&#x529F;&#x80FD;&#xFF1A;&#x4ECE;&#x6807;&#x51C6;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x4E2D;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6837;&#x672C;&#x503C; </p>
</li>
<li><p><strong>np.random.normal(<em>loc=0.0</em>, <em>scale=1.0</em>, <em>size=None</em>)</strong></p>
<p>loc&#xFF1A;float </p>
<p>&#x200B;    &#x6B64;&#x6982;&#x7387;&#x5206;&#x5E03;&#x7684;&#x5747;&#x503C;&#xFF08;&#x5BF9;&#x5E94;&#x7740;&#x6574;&#x4E2A;&#x5206;&#x5E03;&#x7684;&#x4E2D;&#x5FC3;centre&#xFF09;</p>
<p>scale&#xFF1A;float</p>
<p>&#x200B;    &#x6B64;&#x6982;&#x7387;&#x5206;&#x5E03;&#x7684;&#x6807;&#x51C6;&#x5DEE;&#xFF08;&#x5BF9;&#x5E94;&#x4E8E;&#x5206;&#x5E03;&#x7684;&#x5BBD;&#x5EA6;&#xFF0C;scale&#x8D8A;&#x5927;&#x8D8A;&#x77EE;&#x80D6;&#xFF0C;scale&#x8D8A;&#x5C0F;&#xFF0C;&#x8D8A;&#x7626;&#x9AD8;&#xFF09; </p>
<p>size&#xFF1A;int or tuple of ints </p>
<p>&#x200B;    &#x8F93;&#x51FA;&#x7684;shape&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;None&#xFF0C;&#x53EA;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x503C;</p>
</li>
<li><p>np.random.standard_normal(<em>size=None</em>)</p>
<p>&#x8FD4;&#x56DE;&#x6307;&#x5B9A;&#x5F62;&#x72B6;&#x7684;&#x6807;&#x51C6;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
</li>
</ul>
<h5 id="&#x4E3E;&#x4F8B;1&#xFF1A;&#x751F;&#x6210;&#x5747;&#x503C;&#x4E3A;175&#xFF0C;&#x6807;&#x51C6;&#x5DEE;&#x4E3A;1&#x7684;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x6570;&#x636E;&#xFF0C;100000000&#x4E2A;">&#x4E3E;&#x4F8B;1&#xFF1A;&#x751F;&#x6210;&#x5747;&#x503C;&#x4E3A;1.75&#xFF0C;&#x6807;&#x51C6;&#x5DEE;&#x4E3A;1&#x7684;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x6570;&#x636E;&#xFF0C;100000000&#x4E2A;</h5>
<pre><code class="lang-python">x1 = np.random.normal(<span class="hljs-number">1.75</span>, <span class="hljs-number">1</span>, <span class="hljs-number">100000000</span>)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([<span class="hljs-number">2.90646763</span>, <span class="hljs-number">1.46737886</span>, <span class="hljs-number">2.21799024</span>, ..., <span class="hljs-number">1.56047411</span>, <span class="hljs-number">1.87969135</span>,
       <span class="hljs-number">0.9028096</span> ])
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment"># &#x751F;&#x6210;&#x5747;&#x5300;&#x5206;&#x5E03;&#x7684;&#x968F;&#x673A;&#x6570;</span>
x1 = np.random.normal(<span class="hljs-number">1.75</span>, <span class="hljs-number">1</span>, <span class="hljs-number">100000000</span>)

<span class="hljs-comment"># &#x753B;&#x56FE;&#x770B;&#x5206;&#x5E03;&#x72B6;&#x51B5;</span>
<span class="hljs-comment"># 1&#xFF09;&#x521B;&#x5EFA;&#x753B;&#x5E03;</span>
plt.figure(figsize=(<span class="hljs-number">20</span>, <span class="hljs-number">10</span>), dpi=<span class="hljs-number">100</span>)

<span class="hljs-comment"># 2&#xFF09;&#x7ED8;&#x5236;&#x76F4;&#x65B9;&#x56FE;</span>
plt.hist(x1, <span class="hljs-number">1000</span>)

<span class="hljs-comment"># 3&#xFF09;&#x663E;&#x793A;&#x56FE;&#x50CF;</span>
plt.show()
</code></pre>
<p><img src="images/&#x968F;&#x673A;&#x751F;&#x6210;&#x6B63;&#x6001;&#x5206;&#x5E03;.png" alt=""></p>
<p>&#x4F8B;&#x5982;&#xFF1A;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6A21;&#x62DF;&#x751F;&#x6210;&#x4E00;&#x7EC4;&#x80A1;&#x7968;&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x7684;&#x6570;&#x636E;</p>
<h5 id="&#x4E3E;&#x4F8B;2&#xFF1A;&#x968F;&#x673A;&#x751F;&#x6210;4&#x652F;&#x80A1;&#x7968;1&#x5468;&#x7684;&#x4EA4;&#x6613;&#x65E5;&#x6DA8;&#x5E45;&#x6570;&#x636E;">&#x4E3E;&#x4F8B;2&#xFF1A;&#x968F;&#x673A;&#x751F;&#x6210;4&#x652F;&#x80A1;&#x7968;1&#x5468;&#x7684;&#x4EA4;&#x6613;&#x65E5;&#x6DA8;&#x5E45;&#x6570;&#x636E;</h5>
<p>4&#x652F;&#x80A1;&#x7968;&#xFF0C;<strong>&#x4E00;&#x5468;(5&#x5929;)</strong>&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x4F55;&#x83B7;&#x53D6;&#xFF1F;</p>
<ul>
<li>&#x968F;&#x673A;&#x751F;&#x6210;&#x6DA8;&#x8DCC;&#x5E45;&#x5728;&#x67D0;&#x4E2A;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x5185;&#xFF0C;&#x6BD4;&#x5982;&#x5747;&#x503C;0&#xFF0C;&#x65B9;&#x5DEE;1</li>
</ul>
<h5 id="&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;&#x7684;&#x521B;&#x5EFA;">&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;&#x7684;&#x521B;&#x5EFA;</h5>
<pre><code class="lang-python"><span class="hljs-comment"># &#x521B;&#x5EFA;&#x7B26;&#x5408;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;4&#x53EA;&#x80A1;&#x7968;5&#x5929;&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;</span>
stock_change = np.random.normal(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>))
stock_change
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([[ <span class="hljs-number">0.0476585</span> ,  <span class="hljs-number">0.32421568</span>,  <span class="hljs-number">1.50062162</span>,  <span class="hljs-number">0.48230497</span>, -<span class="hljs-number">0.59998822</span>],
       [-<span class="hljs-number">1.92160851</span>,  <span class="hljs-number">2.20430374</span>, -<span class="hljs-number">0.56996263</span>, -<span class="hljs-number">1.44236548</span>,  <span class="hljs-number">0.0165062</span> ],
       [-<span class="hljs-number">0.55710486</span>, -<span class="hljs-number">0.18726488</span>, -<span class="hljs-number">0.39972172</span>,  <span class="hljs-number">0.08580347</span>, -<span class="hljs-number">1.82842225</span>],
       [-<span class="hljs-number">1.22384505</span>, -<span class="hljs-number">0.33199305</span>,  <span class="hljs-number">0.23308845</span>, -<span class="hljs-number">1.20473702</span>, -<span class="hljs-number">0.31753223</span>]])
</code></pre>
<h4 id="142-&#x5747;&#x5300;&#x5206;&#x5E03;">1.4.2 &#x5747;&#x5300;&#x5206;&#x5E03;</h4>
<ul>
<li>np.random.rand(<em>d0</em>, <em>d1</em>, <em>...</em>, <em>dn</em>)<ul>
<li>&#x8FD4;&#x56DE;<strong>[0.0&#xFF0C;1.0)</strong>&#x5185;&#x7684;&#x4E00;&#x7EC4;&#x5747;&#x5300;&#x5206;&#x5E03;&#x7684;&#x6570;&#x3002;</li>
</ul>
</li>
<li><strong>np.random.uniform(<em>low=0.0</em>, <em>high=1.0</em>, <em>size=None</em>)</strong><ul>
<li>&#x529F;&#x80FD;&#xFF1A;&#x4ECE;&#x4E00;&#x4E2A;&#x5747;&#x5300;&#x5206;&#x5E03;[low,high)&#x4E2D;&#x968F;&#x673A;&#x91C7;&#x6837;&#xFF0C;&#x6CE8;&#x610F;&#x5B9A;&#x4E49;&#x57DF;&#x662F;&#x5DE6;&#x95ED;&#x53F3;&#x5F00;&#xFF0C;&#x5373;&#x5305;&#x542B;low&#xFF0C;&#x4E0D;&#x5305;&#x542B;high.  </li>
<li>&#x53C2;&#x6570;&#x4ECB;&#x7ECD;:<ul>
<li>low: &#x91C7;&#x6837;&#x4E0B;&#x754C;&#xFF0C;float&#x7C7B;&#x578B;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;0&#xFF1B;</li>
<li>high: &#x91C7;&#x6837;&#x4E0A;&#x754C;&#xFF0C;float&#x7C7B;&#x578B;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;1&#xFF1B;</li>
<li>size: &#x8F93;&#x51FA;&#x6837;&#x672C;&#x6570;&#x76EE;&#xFF0C;&#x4E3A;int&#x6216;&#x5143;&#x7EC4;(tuple)&#x7C7B;&#x578B;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;size=(m,n,k), &#x5219;&#x8F93;&#x51FA;m<em>n</em>k&#x4E2A;&#x6837;&#x672C;&#xFF0C;&#x7F3A;&#x7701;&#x65F6;&#x8F93;&#x51FA;1&#x4E2A;&#x503C;&#x3002;  </li>
</ul>
</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#xFF1A;ndarray&#x7C7B;&#x578B;&#xFF0C;&#x5176;&#x5F62;&#x72B6;&#x548C;&#x53C2;&#x6570;size&#x4E2D;&#x63CF;&#x8FF0;&#x4E00;&#x81F4;&#x3002;</li>
</ul>
</li>
<li>np.random.randint(<em>low</em>, <em>high=None</em>, <em>size=None</em>, <em>dtype=&apos;l&apos;</em>)<ul>
<li>&#x4ECE;&#x4E00;&#x4E2A;&#x5747;&#x5300;&#x5206;&#x5E03;&#x4E2D;&#x968F;&#x673A;&#x91C7;&#x6837;&#xFF0C;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x6216;N&#x7EF4;&#x6574;&#x6570;&#x6570;&#x7EC4;&#xFF0C;</li>
<li>&#x53D6;&#x6570;&#x8303;&#x56F4;&#xFF1A;&#x82E5;high&#x4E0D;&#x4E3A;None&#x65F6;&#xFF0C;&#x53D6;[low,high)&#x4E4B;&#x95F4;&#x968F;&#x673A;&#x6574;&#x6570;&#xFF0C;&#x5426;&#x5219;&#x53D6;&#x503C;[0,low)&#x4E4B;&#x95F4;&#x968F;&#x673A;&#x6574;&#x6570;&#x3002;</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x751F;&#x6210;&#x5747;&#x5300;&#x5206;&#x5E03;&#x7684;&#x968F;&#x673A;&#x6570;</span>
x2 = np.random.uniform(-<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">100000000</span>)
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([ <span class="hljs-number">0.22411206</span>,  <span class="hljs-number">0.31414671</span>,  <span class="hljs-number">0.85655613</span>, ..., -<span class="hljs-number">0.92972446</span>,
<span class="hljs-number">0.95985223</span>,  <span class="hljs-number">0.23197723</span>])
</code></pre>
<p>&#x753B;&#x56FE;&#x770B;&#x5206;&#x5E03;&#x72B6;&#x51B5;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt

<span class="hljs-comment"># &#x751F;&#x6210;&#x5747;&#x5300;&#x5206;&#x5E03;&#x7684;&#x968F;&#x673A;&#x6570;</span>
x2 = np.random.uniform(-<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">100000000</span>)

<span class="hljs-comment"># &#x753B;&#x56FE;&#x770B;&#x5206;&#x5E03;&#x72B6;&#x51B5;</span>
<span class="hljs-comment"># 1&#xFF09;&#x521B;&#x5EFA;&#x753B;&#x5E03;</span>
plt.figure(figsize=(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>), dpi=<span class="hljs-number">100</span>)

<span class="hljs-comment"># 2&#xFF09;&#x7ED8;&#x5236;&#x76F4;&#x65B9;&#x56FE;</span>
plt.hist(x=x2, bins=<span class="hljs-number">1000</span>)  <span class="hljs-comment"># x&#x4EE3;&#x8868;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;&#xFF0C;bins&#x8868;&#x793A;&#x8981;&#x5212;&#x5206;&#x533A;&#x95F4;&#x6570;</span>

<span class="hljs-comment"># 3&#xFF09;&#x663E;&#x793A;&#x56FE;&#x50CF;</span>
plt.show()
</code></pre>
<p><img src="images/&#x5747;&#x5300;&#x5206;&#x5E03;.png" alt=""></p>
<h2 id="2-&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x3001;&#x5207;&#x7247;">2 &#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x3001;&#x5207;&#x7247;</h2>
<p>&#x4E00;&#x7EF4;&#x3001;&#x4E8C;&#x7EF4;&#x3001;&#x4E09;&#x7EF4;&#x7684;&#x6570;&#x7EC4;&#x5982;&#x4F55;&#x7D22;&#x5F15;&#xFF1F;</p>
<ul>
<li>&#x76F4;&#x63A5;&#x8FDB;&#x884C;&#x7D22;&#x5F15;,&#x5207;&#x7247;</li>
<li>&#x5BF9;&#x8C61;[:, :] -- &#x5148;&#x884C;&#x540E;&#x5217;</li>
</ul>
<p>&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ul>
<li>&#x4E3E;&#x4F8B;&#xFF1A;&#x83B7;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A;&#x80A1;&#x7968;&#x7684;&#x524D;3&#x4E2A;&#x4EA4;&#x6613;&#x65E5;&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4E8C;&#x7EF4;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x4E24;&#x4E2A;&#x7EF4;&#x5EA6; </span>
stock_change[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>:<span class="hljs-number">3</span>]
</code></pre>
<p>&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">array([-<span class="hljs-number">0.03862668</span>, -<span class="hljs-number">1.46128096</span>, -<span class="hljs-number">0.75596237</span>])
</code></pre>
<ul>
<li>&#x4E09;&#x7EF4;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x65B9;&#x5F0F;&#xFF1A;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4E09;&#x7EF4;</span>
a1 = np.array([ [[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>],[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]], [[<span class="hljs-number">12</span>,<span class="hljs-number">3</span>,<span class="hljs-number">34</span>],[<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>]]])
<span class="hljs-comment"># &#x8FD4;&#x56DE;&#x7ED3;&#x679C;</span>
array([[[ <span class="hljs-number">1</span>,  <span class="hljs-number">2</span>,  <span class="hljs-number">3</span>],
        [ <span class="hljs-number">4</span>,  <span class="hljs-number">5</span>,  <span class="hljs-number">6</span>]],

       [[<span class="hljs-number">12</span>,  <span class="hljs-number">3</span>, <span class="hljs-number">34</span>],
        [ <span class="hljs-number">5</span>,  <span class="hljs-number">6</span>,  <span class="hljs-number">7</span>]]])
<span class="hljs-comment"># &#x7D22;&#x5F15;&#x3001;&#x5207;&#x7247;</span>
<span class="hljs-prompt">&gt;&gt;&gt; </span>a1[<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>]   <span class="hljs-comment"># &#x8F93;&#x51FA;: 2</span>
</code></pre>
<h2 id="3-&#x5F62;&#x72B6;&#x4FEE;&#x6539;">3 &#x5F62;&#x72B6;&#x4FEE;&#x6539;</h2>
<h3 id="31-ndarrayreshapeshape-order">3.1 ndarray.reshape(shape, order)</h3>
<ul>
<li>&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5177;&#x6709;&#x76F8;&#x540C;&#x6570;&#x636E;&#x57DF;&#xFF0C;&#x4F46;shape&#x4E0D;&#x4E00;&#x6837;&#x7684;<strong>&#x89C6;&#x56FE;</strong></li>
<li>&#x884C;&#x3001;&#x5217;&#x4E0D;&#x8FDB;&#x884C;&#x4E92;&#x6362;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5728;&#x8F6C;&#x6362;&#x5F62;&#x72B6;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x6CE8;&#x610F;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x5339;&#x914D;</span>
stock_change.reshape([<span class="hljs-number">5</span>, <span class="hljs-number">4</span>])
stock_change.reshape([-<span class="hljs-number">1</span>,<span class="hljs-number">10</span>])  <span class="hljs-comment"># &#x6570;&#x7EC4;&#x7684;&#x5F62;&#x72B6;&#x88AB;&#x4FEE;&#x6539;&#x4E3A;: (2, 10), -1: &#x8868;&#x793A;&#x901A;&#x8FC7;&#x5F85;&#x8BA1;&#x7B97;</span>
</code></pre>
<h3 id="32-ndarrayresizenewshape">3.2 ndarray.resize(new_shape)</h3>
<ul>
<li>&#x4FEE;&#x6539;&#x6570;&#x7EC4;&#x672C;&#x8EAB;&#x7684;&#x5F62;&#x72B6;&#xFF08;&#x9700;&#x8981;&#x4FDD;&#x6301;&#x5143;&#x7D20;&#x4E2A;&#x6570;&#x524D;&#x540E;&#x76F8;&#x540C;&#xFF09;</li>
<li>&#x884C;&#x3001;&#x5217;&#x4E0D;&#x8FDB;&#x884C;&#x4E92;&#x6362;</li>
</ul>
<pre><code class="lang-python">stock_change.resize([<span class="hljs-number">5</span>, <span class="hljs-number">4</span>])

<span class="hljs-comment"># &#x67E5;&#x770B;&#x4FEE;&#x6539;&#x540E;&#x7ED3;&#x679C;</span>
stock_change.shape
(<span class="hljs-number">5</span>, <span class="hljs-number">4</span>)
</code></pre>
<h3 id="33-ndarrayt">3.3 ndarray.T</h3>
<ul>
<li>&#x6570;&#x7EC4;&#x7684;&#x8F6C;&#x7F6E;</li>
<li>&#x5C06;&#x6570;&#x7EC4;&#x7684;&#x884C;&#x3001;&#x5217;&#x8FDB;&#x884C;&#x4E92;&#x6362;</li>
</ul>
<pre><code class="lang-python">stock_change.T.shape
(<span class="hljs-number">4</span>, <span class="hljs-number">5</span>)
</code></pre>
<h2 id="4-&#x7C7B;&#x578B;&#x4FEE;&#x6539;">4 &#x7C7B;&#x578B;&#x4FEE;&#x6539;</h2>
<h3 id="41-ndarrayastypetype">4.1 ndarray.astype(type)</h3>
<ul>
<li>&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x4E86;&#x7C7B;&#x578B;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x7EC4;</li>
</ul>
<pre><code class="lang-python">stock_change.astype(np.int32)
</code></pre>
<h3 id="42-ndarraytostringorder&#x6216;&#x8005;ndarraytobytesorder">4.2 ndarray.tostring([order])&#x6216;&#x8005;ndarray.tobytes([order])</h3>
<ul>
<li>&#x6784;&#x9020;&#x5305;&#x542B;&#x6570;&#x7EC4;&#x4E2D;&#x539F;&#x59CB;&#x6570;&#x636E;&#x5B57;&#x8282;&#x7684;Python&#x5B57;&#x8282;</li>
</ul>
<pre><code class="lang-python">arr = np.array([[[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]], [[<span class="hljs-number">12</span>, <span class="hljs-number">3</span>, <span class="hljs-number">34</span>], [<span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>]]])
arr.tostring()
</code></pre>
<h3 id="43-jupyter&#x8F93;&#x51FA;&#x592A;&#x5927;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x5D29;&#x6E83;&#x95EE;&#x9898;&#x3010;&#x4E86;&#x89E3;&#x3011;">4.3 jupyter&#x8F93;&#x51FA;&#x592A;&#x5927;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x5D29;&#x6E83;&#x95EE;&#x9898;&#x3010;&#x4E86;&#x89E3;&#x3011;</h3>
<p>&#x5982;&#x679C;&#x9047;&#x5230;</p>
<pre><code>IOPub data rate exceeded.
    The notebook server will temporarily stop sending output
    to the client in order to avoid crashing it.
    To change this limit, set the config variable
    `--NotebookApp.iopub_data_rate_limit`.
</code></pre><p>&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x662F;&#x5728;jupyer&#x5F53;&#x4E2D;&#x5BF9;&#x8F93;&#x51FA;&#x7684;&#x5B57;&#x8282;&#x6570;&#x6709;&#x9650;&#x5236;&#xFF0C;&#x9700;&#x8981;&#x53BB;&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<p>&#x521B;&#x5EFA;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-python">jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py
</code></pre>
<p>&#x53D6;&#x6D88;&#x6CE8;&#x91CA;,&#x591A;&#x589E;&#x52A0;</p>
<pre><code class="lang-python"><span class="hljs-comment">## (bytes/sec) Maximum rate at which messages can be sent on iopub before they</span>
<span class="hljs-comment">#  are limited.</span>
c.NotebookApp.iopub_data_rate_limit = <span class="hljs-number">10000000</span>
</code></pre>
<p><strong>&#x4F46;&#x662F;&#x4E0D;&#x5EFA;&#x8BAE;&#x8FD9;&#x6837;&#x53BB;&#x4FEE;&#x6539;&#xFF0C;jupyter&#x8F93;&#x51FA;&#x592A;&#x5927;&#x4F1A;&#x5D29;&#x6E83;</strong></p>
<h2 id="5-&#x6570;&#x7EC4;&#x7684;&#x53BB;&#x91CD;">5 &#x6570;&#x7EC4;&#x7684;&#x53BB;&#x91CD;</h2>
<h3 id="51-npunique">5.1 np.unique()</h3>
<pre><code class="lang-python">temp = np.array([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>],[<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]])
<span class="hljs-prompt">&gt;&gt;&gt; </span>np.unique(temp)
array([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>])
</code></pre>
<h2 id="6-&#x5C0F;&#x7ED3;">6 &#x5C0F;&#x7ED3;</h2>
<ul>
<li><p>&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x3010;&#x638C;&#x63E1;&#x3011;</p>
<ul>
<li>&#x751F;&#x6210;0&#x548C;1&#x7684;&#x6570;&#x7EC4;<ul>
<li>np.ones()</li>
<li>np.ones_like()</li>
</ul>
</li>
<li>&#x4ECE;&#x73B0;&#x6709;&#x6570;&#x7EC4;&#x4E2D;&#x751F;&#x6210;<ul>
<li>np.array -- &#x6DF1;&#x62F7;&#x8D1D;</li>
<li>np.asarray -- &#x6D45;&#x62F7;&#x8D1D;</li>
</ul>
</li>
<li><p>&#x751F;&#x6210;&#x56FA;&#x5B9A;&#x8303;&#x56F4;&#x6570;&#x7EC4;</p>
<ul>
<li>np.linspace()<ul>
<li>nun -- &#x751F;&#x6210;&#x7B49;&#x95F4;&#x9694;&#x7684;&#x591A;&#x5C11;&#x4E2A;</li>
</ul>
</li>
<li>np.arange()<ul>
<li>step -- &#x6BCF;&#x95F4;&#x9694;&#x591A;&#x5C11;&#x751F;&#x6210;&#x6570;&#x636E;</li>
</ul>
</li>
<li>np.logspace()<ul>
<li>&#x751F;&#x6210;&#x4EE5;10&#x7684;N&#x6B21;&#x5E42;&#x7684;&#x6570;&#x636E;</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x751F;&#x5C42;&#x968F;&#x673A;&#x6570;&#x7EC4;</p>
<ul>
<li>&#x6B63;&#x6001;&#x5206;&#x5E03;<ul>
<li>&#x91CC;&#x9762;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x7684;&#x53C2;&#x6570;:&#x5747;&#x503C;:u, &#x6807;&#x51C6;&#x5DEE;:&#x3C3;<ul>
<li>u -- &#x51B3;&#x5B9A;&#x4E86;&#x8FD9;&#x4E2A;&#x56FE;&#x5F62;&#x7684;&#x5DE6;&#x53F3;&#x4F4D;&#x7F6E;</li>
<li>&#x3C3; -- &#x51B3;&#x5B9A;&#x4E86;&#x8FD9;&#x4E2A;&#x56FE;&#x5F62;&#x662F;&#x7626;&#x9AD8;&#x8FD8;&#x662F;&#x77EE;&#x80D6;</li>
</ul>
</li>
<li>np.random.randn()</li>
<li>np.random.normal(0, 1, 100)</li>
</ul>
</li>
<li>&#x5747;&#x5300;<ul>
<li>np.random.rand()</li>
<li>np.random.uniform(0, 1, 100)</li>
<li>np.random.randint(0, 10, 10)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x3010;&#x77E5;&#x9053;&#x3011;</p>
<ul>
<li>&#x76F4;&#x63A5;&#x8FDB;&#x884C;&#x7D22;&#x5F15;,&#x5207;&#x7247;</li>
<li>&#x5BF9;&#x8C61;[:, :] -- &#x5148;&#x884C;&#x540E;&#x5217;</li>
</ul>
</li>
<li><p>&#x6570;&#x7EC4;&#x5F62;&#x72B6;&#x6539;&#x53D8;&#x3010;&#x638C;&#x63E1;&#x3011;</p>
<ul>
<li>&#x5BF9;&#x8C61;.reshape()<ul>
<li>&#x6CA1;&#x6709;&#x8FDB;&#x884C;&#x884C;&#x5217;&#x4E92;&#x6362;,&#x65B0;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;ndarray</li>
</ul>
</li>
<li>&#x5BF9;&#x8C61;.resize()<ul>
<li>&#x6CA1;&#x6709;&#x8FDB;&#x884C;&#x884C;&#x5217;&#x4E92;&#x6362;,&#x4FEE;&#x6539;&#x539F;&#x6765;&#x7684;ndarray</li>
</ul>
</li>
<li>&#x5BF9;&#x8C61;.T<ul>
<li>&#x8FDB;&#x884C;&#x4E86;&#x884C;&#x5217;&#x4E92;&#x6362;</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x6570;&#x7EC4;&#x53BB;&#x91CD;&#x3010;&#x77E5;&#x9053;&#x3011;</p>
<ul>
<li>np.unique(&#x5BF9;&#x8C61;)</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Numpy/section2.html" class="navigation navigation-prev " aria-label="Previous page: N维数组-ndarray"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../Numpy/section4.html" class="navigation navigation-next " aria-label="Next page: ndarray运算"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"katex":{},"expandable-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
